Ext.define('com.hh.workflow.task.TaskList', {
	extend : 'com.hh.global.SimpleGridPanelWindow',
	title : '我的工作',
	action : 'workflow-Task-',
	constructor : function(config) {
		this.config = config || {};
		this.callParent(arguments);
	},
	getStoreFields : function() {
		return ['id', 'name', 'managerType', 'pdid', 'activityId', 'piName',
				'createTime', 'piid', 'startUserName'];
	},
	getGridColumns : function() {
		return [{
					text : 'id',
					flex : 1,
					dataIndex : 'id',
					hidden : true
				}, {
					text : '经办类型',
					dataIndex : 'managerType',
					width : 60
				}, {
					text : '流程标识',
					dataIndex : 'piid',
					flex : 1
				}, {
					text : '流程名称',
					dataIndex : 'piName',
					width : 300
				}, {
					text : '节点名称',
					flex : 1,
					dataIndex : 'name'
				}, {
					text : '任务创建时间',
					dataIndex : 'createTime',
					width : 200,
					renderer : Ext.util.Format.dateRenderer('Y年m月d日 H时i分s秒')
				}];
	},
	getMyToolbarItem : function(type) {
		var page = this;
		if (type == 'manager') {
			return {
				icon : 'struts-image?path=com/hh/workflow/img/shape_square_edit.png',
				text : '办理',
				handler : function() {
					page.doManager();
				}
			};
		} else if (type == 'select') {
			return {
				iconCls : 'search',
				text : '查看历史',
				handler : function() {
					page.doSelectHi();
				}
			};
		} else if (type == 'claim') {
			return {
				icon : 'struts-image?path=com/hh/workflow/img/shape_square_edit.png',
				text : '领取',
				handler : function() {
					page.doClaim();
				}
			};
		}
	},
	doClaim : function() {
		var record = this.getGridRecord();
		if (record == null) {
			ExtFrame.info("请选中您要办理的数据！！");
			return;
		}
		Request.request('workflow-Task-claim', {
					taskId : record.get("id")
				});
	},
	doSelectHi : function() {
		var record = this.getGridRecord();
		if (record == null) {
			ExtFrame.info("请选中您要查看历史的流程！！");
			return;
		}
		var win = ExtUtil.open('com.hh.workflow.task.HiTaskList', {
					parentPanel : this,
					extraParams : {
						piid : record.get("piid"),
						pdid : record.get("pdid")
					}
				});
	},
	getTbarItems : function() {
		var panel = this;
		return [this.getMyToolbarItem("manager"),
				this.getMyToolbarItem("select")];
	},
	statics : {
		doManager : function(grid, paramMap) {
			var record = grid.getSelectionModel().getLastSelected();
			if (Util.isNull(record)) {
				ExtFrame.info("请选中要办理的数据！");
			} else {
				Request.request('workflow-Task-manager', {
							activityId : record.get("activityId"),
							taskId : record.get("id"),
							actionType : paramMap.actionType
						}, function(result) {
							if (result.href) {
								var callbackRefresh = function() {
									grid.getStore().load();
								}
								var params = {};
								Ext
										.apply(params,
												Ext.decode(result.hrefParams));
								params.objectId = result.objectId;
								params.taskId = result.taskId;
								params.piid = result.piid;
								params.pdid = record.get("pdid");
								params.activityId = record.get("activityId");
								params.title = record.get("piName") + "（"
										+ record.get("name") + "）";
								params.piName = record.get("piName");
								params.actName = record.get("name");
								params.callbackRefresh = callbackRefresh;
								params.actConfig = result;
								params.actionType = paramMap.actionType;
								ExtUtil.open(result.href, params);
							} else {
								ExtFrame.info("没指定表单！");
							}
						});
			}
		}
	},
	doManager : function() {
		com.hh.workflow.task.TaskList.doManager(this.grid, {
					actionType : 'manager'
				});
	}
});